<!DOCTYPE html>
<html lang="zh">
<head>
 <meta charset="UTF-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 <title>12.计算属性.html</title>
 <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.js"></script>
 <style>
   body{
     background-color: #eee;
   }
   #app{
     background-color:#fff;
     width: 500px;
     margin: 50px auto;
     box-shadow: 3px 3px 3px rgba(0 , 0, 0, 0.5);padding:2em;
    }
   .box{
     padding: 1em;
     border:1px solid #ccc;
     margin:1em;
   }
   </style>
 </head>
    <div id="app">
      <p v-for="(item,index) in list "> 产品：{{item.name}}&nbsp;&nbsp;&nbsp;&nbsp;价格：{{item.price}}</p>
     <h4 v>总价格：{{totalmoney}}</h4>
     <p>单价超过10000的商品个数：{{shopnum}}</p>
    </div>
    <script>
     let vw = new Vue({
        el:'#app',
        data:{
         list: [{name:'phone',price:9000},
              {name:'ipaid',price:7000},
              {name:'mac',price:12000}]
      },
      computed:{
        totalmoney :function(){
          // let sumprice = this.list[0].price+this.list[1].price+this.list[2].price
          let sumprice = 0
          this.list.forEach((value, index, array) => {
           sumprice += value.price
          })
          return sumprice
        },
        shopnum:function () {
          let num = 0
          this.list.forEach((value, index, array) => {
            if(value.price>=10000){
              num = ++num
            }
            
        })
        return num
        }
      }
    })
    </script>
 </body>
</html>